package com.longtop.framework.sys.log.service;

import com.longtop.framework.base.BaseService;
import com.longtop.framework.common.QueryConditions;
import com.longtop.framework.common.QueryResult;
import com.longtop.framework.sys.log.model.TSysLog;
import com.longtop.framework.util.DateUtil;
import com.longtop.framework.util.UniqueKeyUtil;

public class LogService extends BaseService {

	public static final String BEAN_ID = "logService";

	/**
	 * 依据条件，读取代码信息列表
	 * 
	 * @param queryConditions
	 *            查询条件
	 * @param pageNo
	 *            查询结果的起始页码。
	 * @param pageSize
	 *            查询结果的最大行数。如果不需要，则设置为-1
	 * @return
	 */
	public QueryResult loadLog(QueryConditions queryConditions, int pageNo, int pageSize) {

		String orderBy = "logTime desc";
		queryConditions.setOrderBy(orderBy);

		return this.loadByConditions(queryConditions, pageNo, pageSize, TSysLog.class);
	}

	public void saveLog(String moduleId, String opType, String opInfo, String operCode, String operName, String ipaddr) {
		String id = UniqueKeyUtil.getUuidKey();
		TSysLog log = new TSysLog();
		log.setLogId(id);
		log.setModuleId(moduleId);
		log.setLogInfo(opInfo);
		log.setUserId(operCode);
		log.setUserName(operName);
		log.setIpAddr(ipaddr);
		log.setLogTime(java.sql.Timestamp.valueOf(DateUtil.formatDateTime()));
		save(log);
	}
}